package com.rest.demo.Controller;

import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import com.rest.demo.Service.DysmtXxjj;

import com.rest.demo.util.Md5;
import com.rest.demo.util.PYEncryption;
import com.rest.demo.util.Sha256Util;
import com.rest.demo.util.UrlEncode;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Data
@RestController
@RequestMapping("/DysmtHouseMoney")//整个路由路径


public class GetUserHouseMoney {
    @Value("${APiUrl.DysmtWxjjToken}")
    public String MainUrl;//请求Token的主地址
    @Value("${APiUrl.DysmtWxjjHouseInfo}")
    public String DysmtWxjjHouseInfoUrl;//维修基金详细请求的地址


    UrlEncode UrlEncode = new UrlEncode();//转码定义对象
    DysmtXxjj Server = new DysmtXxjj();//定义服务对象

    @RequestMapping("/Info")//通过身份证及姓名查询
    public String getCode3() throws Exception {
//        System.out.println(MainUrl);


        JSONObject Jsonparam = new JSONObject();
        Jsonparam.put("Appid", "FIXF789654123");
        Jsonparam.put("AppSecret", "3e00eaede36c453aa4f70ad4517bc95f");
//        Sha256Util.getSHA256("Jsonparam");
//        System.out.println("ssssss"+       Sha256Util.getSHA256("Jsonparam"));

        String JsonparamUrl = UrlEncode.Encode(PYEncryption.encrypt(Jsonparam.toString()));//将参数转码为UrlEncode

        return Server.PostformData(MainUrl, JsonparamUrl);

    }

    @RequestMapping("/HouseMoneyInfo")//通过身份证及姓名查询

    public String getDetail(String OwnerName, String CertificateNum) throws Exception {

        System.out.println(PYEncryption.decrypt(getCode3()));
        String Token = JSONObject.parseObject(PYEncryption.decrypt(getCode3())).getString("Token");
        System.out.println(Token);
        JSONObject Jsonparam = new JSONObject();//请求参数
        Jsonparam.put("Token", Token);
        Jsonparam.put("OwnerName", OwnerName);
        Jsonparam.put("CertificateNum", CertificateNum);
        System.out.println(Jsonparam);
        String JsonparamUrl = UrlEncode.Encode(PYEncryption.encrypt(Jsonparam.toString()));//将参数转码为UrlEncode

        System.out.println( Server.PostDataInfo(DysmtWxjjHouseInfoUrl, JsonparamUrl));
        String Token2 = JSONObject.parseObject(PYEncryption.decrypt(getCode3())).getString("Token");
        String nr = Server.PostDataInfo(DysmtWxjjHouseInfoUrl, JsonparamUrl).getString("Content");

String Rz = PYEncryption.decrypt(nr);
        return  Rz;
    }


}
